package org.example.controller;


import org.example.entity.User;
import org.example.entity.vo.LoginUser;
import org.example.entity.vo.LoginUserInfo;
import org.example.result.R;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Copyright: Copyright (c) 2022 Asiainfo
 *
 * @ClassName: com.zxp.springsecurity.controller.LoginController
 * @Description: 该类的功能描述
 * @version: v1.0.0
 * @author: 炫沙糖桔的鹏仔
 * @date: 2022/8/8 16:12
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2022/8/8      炫沙糖桔的鹏仔          v1.0.0               修改原因
 */
@RestController
public class LoginController {

    @Autowired
    UserService userService;
//    前端登录的一般流程
//    1. 前端发送请求到后端,后端校验数据库返回一个jwt
//    2. 前端将jwt存储到cookie中
//    3. 前端将cookie发送到后端,后端校验jwt,校验成功返回结果 jwt解析出id用户用户信息查询
//    4. 后端返回携带权限数据的结果
    @PostMapping("/user/login")
    public R login(@RequestBody LoginUserInfo user) {
        System.out.println(user);
        return userService.login(user);
    }

    @GetMapping("/user/logout")
    public R logout() {
        return userService.logout();
    }
}
